<template>
  <div class="menu">
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <el-button @click="$router.push({ name: 'advertSpace-create' })">添加广告位</el-button>
      </div>
      <el-table
        :data="list"
        style="width: 100%">
        <el-table-column
          prop="spaceKey"
          label="spaceKey"
          min-width="150">
        </el-table-column>
        <el-table-column
          prop="name"
          label="广告位名称"
          min-width="150">
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="创建时间"
          min-width="150">
        </el-table-column>
        <el-table-column
          prop="updateTime"
          label="更新时间"
          min-width="150">
        </el-table-column>
        <el-table-column
          label="操作"
          min-width="100">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
  </div>
</template>

<script lang="ts">
import Vue from 'vue'
import { getEditMenuInfo, changeState } from '@/services/advert'

export default Vue.extend({
  name: 'advertIndex',
  data () {
    return {
      list: [] // 菜单列表
    }
  },

  created () {
    this.loadAllAdvert()
  },

  methods: {
    async loadAllAdvert () {
      const { data } = await getEditMenuInfo()
      this.list = data.content
    },

    handleEdit (item: any) {
      this.$router.push({
        name: 'advertSpace-edit',
        params: {
          id: item.id
        }
      })
    },

    async onStateChange (course: any) {
      course.isStatusLoading = true
      await changeState({
        id: course.id,
        status: course.status
      })
      this.$message.success(`${course.status === 0 ? '下线' : '上线'}成功`)
      course.isStatusLoading = false
    }
  }
})
</script>

<style lang="scss" scoped></style>
